package com.swordxu.yim.server.msgserver;

import com.alibaba.fastjson.JSON;
import com.swordxu.yim.server.packet.Message;
import com.swordxu.yim.server.session.DefaultSessionMananger;
import com.swordxu.yim.server.session.SessionManager;
import com.swordxu.yim.server.session.YimSession;
import com.swordxu.yim.server.tool.IMPacketDispatcher;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.net.InetAddress;

/**
 * 消息服务器handler类
 * Created by user063 on 2014/12/26.
 */
public class MsgServerHandler extends SimpleChannelInboundHandler<String> {
    static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    static final SessionManager sm = new DefaultSessionMananger();

    @Override
    public void channelActive(final ChannelHandlerContext ctx) throws Exception {
        System.out.println("有人连接消息服务器!ip:" + ctx.channel().remoteAddress());
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        IMPacketDispatcher.dispatch(msg.toString(), ctx);
    }
}
